package com.yenlien.traceyun.plant.controller;

import com.yenlien.traceyun.plant.dao.TouShuDao;
import com.yenlien.traceyun.plant.entity.TouShu;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

/**
 * @Date 2021/9/9
 * @Author jiaLong
 * @Descript
 */
@RequestMapping("/toushu")
@RestController
public class TouShuController extends BaseController {

    @Autowired
    private TouShuDao touShuDao;


    @GetMapping(value = "/findById/{id}")
    public Object findById(@PathVariable("id") String id) {
        return success(touShuDao.findById(id));
    }

    @PostMapping(value = "/findList")
    public Object findById(@RequestBody TouShu touShu) {
        Pageable pageable = PageRequest.of(touShu.getPage(), touShu.getPageSize(), Sort.Direction.DESC, ("createTime"));
        return buildPage(touShuDao.findAll(pageable));
    }

    @PostMapping(value = "/save")
    public Object save(@RequestBody TouShu touShu) {
        touShuDao.save(touShu);
        return success("success");
    }


}
